using UnityEngine;

public class BulletFire : MonoBehaviour
{
	public SpriteRenderer sr;

	public Sprite[] fireSprites;

	public SpriteRenderer laser;

	public GameObject laserMask;

	public ParticleSystem ps;

	public GameObject[] psObject;

	public Vector2 hitPoint;

	private void Start()
	{
		if (fireSprites.Length != 0)
		{
			sr.sprite = fireSprites[Random.Range(0, fireSprites.Length)];
			base.transform.localScale *= Random.Range(0.8f, 1.2f);
		}
		if (!laser && !ps)
		{
			Object.Destroy(base.gameObject, 0.02f);
		}
		if ((bool)ps)
		{
			ps.transform.SetParent(null);
			ps.transform.position = base.transform.position;
			ps.transform.rotation = base.transform.rotation;
		}
	}

	private void FixedUpdate()
	{
		if (!laser)
		{
			return;
		}
		Vector3 vector = base.transform.TransformDirection(Vector3.right);
		laser.transform.localScale = new Vector3(2f * Random.Range(1f, 2f), Random.Range(0.5f, 2f), 0f);
		laserMask.transform.localPosition = new Vector3(50f, 0f, 0f);
		RaycastHit2D[] array = Physics2D.RaycastAll(base.transform.position, vector, 100f, Ground.shootableLayerMask);
		if (array.Length == 0)
		{
			return;
		}
		float num = 200f;
		RaycastHit2D[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit2D raycastHit2D = array2[i];
			if (!(raycastHit2D.collider != null) || !(raycastHit2D.collider.tag == "Body"))
			{
				continue;
			}
			BodyPart component = raycastHit2D.collider.GetComponent<BodyPart>();
			if ((bool)component)
			{
				num -= component.resistance;
				if (num <= 0f)
				{
					laserMask.transform.localPosition = new Vector3(raycastHit2D.distance, 0f, 0f);
					break;
				}
			}
		}
	}

	private void Update()
	{
		if ((bool)ps)
		{
			ps.transform.position = base.transform.position;
			ps.transform.rotation = base.transform.rotation;
		}
	}

	public void StartPs()
	{
		if (psObject.Length != 0)
		{
			GameObject[] array = psObject;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].SetActive(value: true);
			}
		}
		ps.Play();
	}

	public void StopPs()
	{
		if (psObject.Length != 0)
		{
			GameObject[] array = psObject;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].SetActive(value: false);
			}
		}
		ps.Stop();
	}
}
